/**
 * 
 */
package com.xinghou.platform.file.chain.impl;

import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.config.ConfigParser;
import org.apache.commons.chain.impl.CatalogFactoryBase;

import com.xinghou.platform.file.chain.BaseChain;

/**
 * @author wxtdy
 *
 */
public class BaseChainImpl implements BaseChain {

	private  ConfigParser parser;  
	
	private  Catalog catalog;
	
	private String configPath;
	
	private String chainName;
	
	private void configuration() throws Exception{
		parser.parse(this.getClass().getResource(configPath));  
		catalog = CatalogFactoryBase.getInstance().getCatalog();  
	}
	
	public BaseChainImpl(String chainName, String configPath){
		parser = new  ConfigParser();  
		this.configPath = configPath;
		this.chainName = chainName;
		try {
			configuration();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void execute(Context context) throws Exception {
		catalog.getCommand(chainName).execute(context);
	}

}
